package io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Test03 {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        // 被复制的文件
        File fromFile = new File("D:/1.txt");
        // 复制出来的文件
        File toFile = new File("D:/4.txt");
        InputStream is = null;
        OutputStream os = null;
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            is = new FileInputStream(fromFile);
            os = new FileOutputStream(toFile);
            // 创建缓冲流
            bis = new BufferedInputStream(is);
            bos = new BufferedOutputStream(os);
            int content = bis.read();
            while (content != -1) {
                // 使用缓冲流写数据
                bos.write(content);
                // 刷新
                bos.flush();
                content = bis.read();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                is.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        long endTime = System.currentTimeMillis();
        System.out.println("视频复制完成,耗时:" + (endTime - startTime) + "毫秒");

    }

}